<template>
  <div class="publish-wrapper">
    <div class="form-box">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="发布平台" prop="platform">
          <el-radio-group v-model="form.platform">
            <el-radio label="0" value="0">PC端</el-radio>
            <el-radio label="1" value="1">小程序</el-radio>
            <el-radio label="2" value="2">APP</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="发布内容" prop="content">
          <el-input
            placeholder="请输入发布内容，请使用“enter”键换行，请不要输入html标签，因渲染公告的时候不支持"
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 12 }"
            v-model="form.content"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handlePublish">立即发布</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { publishNotice } from "@/api";
export default {
  data() {
    return {
      rules: {
        platform: [
          { required: true, message: "请选择发布平台", trigger: "blur" },
        ],
        content: [
          { required: true, message: "请填写发布内容", trigger: "blur" },
        ],
      },
      form: {
        platform: "",
        content: "",
        cardType: "0",
      },
    };
  },
  methods: {
    handlePublish() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          const params = {
            ...this.form,
          };
          console.log("🚀 ~ handlePublish ~ params:", params);
          publishNotice(params).then((res) => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "发布成功",
              });
            }
          });
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.publish-wrapper {
  padding: 24px;
  background-color: #fff;
  height: calc(100vh - 54px);
  .form-box {
    width: 500px;
  }
}
</style>
